
package com.linln.admin.system.task;


import com.linln.modules.system.domain.SysLog;
import com.linln.modules.system.service.SysLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;


/**
 * (需要异步执行的)通用任务类
 * 实现方式：@Async注解
 * 注意事项：http://blog.csdn.net/haiyangzhishen/article/details/46930677
 *
 * @author lizhou
 * @version 1.0
 * @Date 2018年01月29日 13时44分
 */
@Component
public class CommonTask {
    private static final Logger logger = LoggerFactory.getLogger(CommonTask.class);

    @Autowired
    private SysLogService sysLogService;


    /**
     * 通用的异步记录用户的操作日志
     *
     * @param logs
     * @return Object ,防止出现AOPException:Null return value from advice does not match primitive return type for...
     */
    @Async
    public Object log(SysLog logs) {
        try {
            sysLogService.save(logs);
            logger.debug("异步保存操作日志完成");
            return true;
        } catch (Exception e) {
            logger.error("异步保存操作日志发生异常:logs=" + logs + " \n 异常信息:" + e.getMessage() + ",\n 请求的数据：" + logs, e);
            return false;
        }
    }


}
